home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / UNIX Cracking / MacCracSource.sit / MacCrac.source / Source / crack-supp.c < prev    next >
Text File  |  1995-02-07  |  6KB  |  261 lines

  1. /*
  2.  * This program is copyright Alec Muffett 1991 except for some portions of
  3.  * code in "crack-fcrypt.c" which are copyright Robert Baldwin, Icarus Sparry
  4.  * and Alec Muffett.  The author(s) disclaims all responsibility or liability
  5.  * with respect to it's usage or its effect upon hardware or computer
  6.  * systems, and maintain copyright as set out in the "LICENCE" document which
  7.  * accompanies distributions of Crack v4.0 and upwards.
  8.  */
  9.  
  10. #include "crack.h"
  11. #include <time.h>
  12. #include <stdio.h>
  13.  
  14. #define THEALERT 130
  15. #define NIL        0L
  16.  
  17. int
  18. gethostname (name, namelen)
  19.     char *name;
  20.     int namelen;
  21. {
  22.  
  23. strcpy(name, "Macintosh");
  24. namelen = 9;
  25.  
  26. }
  27.  
  28. /* special note at bottom of screen */
  29. void
  30. SysLog (fmt, a, b, c, d, e, f, g, h, i, j)
  31.     char *fmt;
  32.     long int a, b, c, d, e, f, g, h, i, j;
  33. {
  34. Point penplace, originalpen;
  35. GrafPtr thePort;
  36. Rect tempRect;
  37. char buffer[STRINGSIZE], buffer2[STRINGSIZE];
  38. time_t t;
  39.  
  40. time(&t);
  41. sprintf (buffer,"MacCrac - %-15.15s     ", ctime (&t) + 4);
  42. sprintf (buffer2,fmt, a, b, c, d, e, f, g, h, i, j);
  43.  
  44.     GetPort(&thePort);
  45.     GetPen(&originalpen);
  46.  
  47. MoveTo(0, (thePort->portRect.bottom) - 10);
  48. ForeColor(whiteColor);
  49. BackColor(magentaColor);
  50. DrawText (buffer, 0,  strlen(buffer) );
  51. DrawText (buffer2, 0, strlen(buffer2));
  52.        
  53.        /* draw box to end of window */
  54.        BackColor(magentaColor);
  55.        ForeColor(magentaColor);
  56.        GetPen(&penplace);
  57.        tempRect.top  = (penplace.v) - 10;
  58.        tempRect.left = (penplace.h);
  59.        tempRect.bottom = (penplace.v) + 2;
  60.        tempRect.right = (thePort->portRect.right);
  61.        PaintRect(&tempRect);
  62.        
  63.        ForeColor(blackColor);
  64.        BackColor(whiteColor);
  65.  
  66. MoveTo(originalpen.h, originalpen.v);
  67.  
  68. }
  69.  
  70. /* log anything to datafile. */
  71.  
  72. void
  73. Log (fmt, a, b, c, d, e, f, g, h, i, j)
  74.     char *fmt;
  75.     long int a, b, c, d, e, f, g, h, i, j;
  76.  
  77.  
  78. {
  79.     time_t t;
  80.     FILE *fp;
  81.     Str255 badlog = "Error opening Logfile.";
  82.     char buffer[STRINGSIZE], buffer2[STRINGSIZE];
  83.     GrafPtr thePort;
  84.     Point penplace;
  85.     TEHandle docTE;
  86.     Rect tempRect;
  87.     time (&t);
  88.  
  89. /* ALWAYS WRITE TO A LOG */
  90.     if ((fp = fopen (opfile, "a")) == NULL)
  91.     {
  92.     ParamText(badlog, NIL, NIL, NIL);
  93.     Alert (THEALERT, NIL);
  94.     exit(1);
  95.     }
  96.  
  97.     fprintf (fp,"pwc: %-15.15s ", ctime (&t) + 4);
  98.     fprintf (fp,fmt, a, b, c, d, e, f, g, h, i, j);
  99.     fclose (fp);
  100.  
  101.  
  102.  
  103. /* sometimes write to the screen */
  104.  
  105.     if (foreground_bool)
  106.     {
  107.     sprintf (buffer,"pwc: %-15.15s ", ctime (&t) + 4);
  108.     sprintf (buffer2,fmt, a, b, c, d, e, f, g, h, i, j);
  109.  
  110.     GetPort(&thePort);
  111.     GetPen(&penplace);
  112.     Move(-(penplace.h),13);
  113.  
  114.  
  115.     if (penplace.v >= (thePort->portRect.bottom - 35))
  116.         {
  117.        MoveTo(0,10);
  118.     /*   ScrollRect(&thePort->portRect, 0, -20, thePort->visRgn);*/
  119.         }
  120.  
  121.        DrawText (buffer, 0,  strlen(buffer) );
  122.        DrawText (buffer2, 0, (strlen(buffer2) -1 ));
  123.        
  124.        /* draw box to end of window */
  125.        ForeColor(whiteColor);
  126.        GetPen(&penplace);
  127.        tempRect.top  = (penplace.v) - 13;
  128.        tempRect.left = (penplace.h);
  129.        tempRect.bottom = (penplace.v);
  130.        tempRect.right = (thePort->portRect.right);
  131.        PaintRect(&tempRect);
  132.        
  133.        ForeColor(blackColor);
  134.     }
  135. }
  136.  
  137.  
  138. /* print a guess, giving a single place to mod where necessary */
  139.  
  140. void
  141. PrintGuess (eptr, guess)
  142.     register struct USER *eptr;
  143.     char *guess;
  144. {
  145.     eptr -> done = 1;
  146.     eptr -> passwd_txt = Clone (guess);    /* ESSENTIAL to FeedBack() */
  147.  
  148.     if (!eptr -> passwd_txt)
  149.     {
  150.     eptr -> passwd_txt = "<Ran out of memory logging this password>";
  151.     }
  152.     ForeColor(redColor);
  153.     Log ("Guessed %s%s (%s in %s) [%s] %s\n",
  154.      (eptr -> passwd.pw_uid ? "" : "ROOT PASSWORD "),
  155.      eptr -> passwd.pw_name,
  156.      eptr -> passwd.pw_shell,
  157.      eptr -> filename,
  158.      guess,
  159.      eptr -> passwd.pw_passwd);
  160.     if (foreground_bool)
  161.         SysLog("PASSWORD(S) FOUND THIS SESSION!  Check the log.");
  162.  
  163. }
  164.  
  165.  
  166. /* write a pointfile out */
  167.  
  168. int
  169. SetPoint (dict, rule, usernum, username)
  170.     char *dict;
  171.     char *rule;
  172.     int usernum;
  173.     char *username;
  174. {
  175.     FILE *fp;
  176.     time_t t;
  177.     Str255 badpoint = " Error opening Point File for writing.";
  178.  
  179.     if (!(fp = fopen (pointfile, "w")))
  180.     {
  181.     ParamText(badpoint, NIL, NIL, NIL);
  182.     Alert (THEALERT, NIL);
  183.     return (-1);
  184.     }
  185.     time (&t);
  186.  
  187.     fprintf (fp, "host=%s pid=%d pointtime=%s", this_hostname, pid, ctime (&t));
  188.     fprintf (fp, "%s\n", this_hostname);
  189.     fprintf (fp, "%s\n", dict);
  190.     fprintf (fp, "%s\n", rule);
  191.     fprintf (fp, "%d\n", usernum);
  192.     fprintf (fp, "%s\n", username);
  193.  
  194.     fclose (fp);
  195.  
  196.     return (0);
  197. }
  198. /* read a pointfile in... */
  199.  
  200. int
  201. GetPoint (pf)
  202.     char *pf;
  203. {
  204.     FILE *fp;
  205.     char buffer[STRINGSIZE];
  206.  
  207.     if (!(fp = fopen (pf, "r")))
  208.     {
  209.     SysLog("Error:  Can't open Point File for reading.");
  210.     Log ("Error:  Can't open Point File for reading.");
  211.     return (-1);
  212.     }
  213.     /* junk */
  214.     if (!fgets (buffer, STRINGSIZE, fp))
  215.     {
  216.     return (-2);
  217.     }
  218.     /* hostname */
  219.     if (!fgets (old_hostname, STRINGSIZE, fp))
  220.     {
  221.     return (-3);
  222.     }
  223.     /* dictname */
  224.     if (!fgets (old_dictname, STRINGSIZE, fp))
  225.     {
  226.     return (-4);
  227.     }
  228.     /* rule */
  229.     if (!fgets (old_rule, STRINGSIZE, fp))
  230.     {
  231.     return (-5);
  232.     }
  233.     /* usernum */
  234.     if (!fgets (buffer, STRINGSIZE, fp))
  235.     {
  236.     return (-6);
  237.     }
  238.     /* username */
  239.     if (!fgets (old_username, STRINGSIZE, fp))
  240.     {
  241.     return (-7);
  242.     }
  243.     Trim (old_hostname);
  244.  
  245.     if (strcmp (old_hostname, this_hostname))
  246.     {
  247.     return (-8);
  248.     }
  249.     Trim (old_dictname);
  250.     Trim (old_rule);
  251.  
  252.     old_usernum = atoi (buffer);
  253.  
  254.     Trim (old_username);
  255.  
  256.     fclose (fp);
  257.  
  258.  return (0);
  259.  
  260.  }
  261.